'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 来袭
 * @author sundbcn@gmail.com (sun debing)
 */

var _ = require('lodash');
var dataApi = require('../libs/dataApi');

exports.getRebelRewardConf = function (rebel_id) {
    return dataApi.rebel_reward.findById(rebel_id);
};

exports.getRebelConf = function (rebel_id) {
    return _getRebelConf(rebel_id);
};

exports.getRebelWaveLength = function (rebel_id) {
    var rebel_conf = _getWaveConf(rebel_id);
    if (!rebel_conf) {
        return 0;
    }
    return _.size(rebel_conf);
};

/**
 * 获取来袭的前置
 * @param  {[type]} rebel_id [description]
 * @return {[type]}          [description]
 */
exports.getPreRebelId = function (rebel_id) {
    var rebel_conf = _getRebelConf(rebel_id);
    if (!rebel_conf) {
        console.error('rebel_conf type can not found:' + rebel_id);
        return null;
    }
    return rebel_conf.need_id;
};

/**
 * 获取来袭的技能
 * @param  {[type]} rebel_id [description]
 * @return {[type]}          [description]
 */
exports.getRebelSkill = function (skill_id) {
    var rebel_conf = _getRebelSkillConf(skill_id);
    if (!rebel_conf) {
        console.error('rebel_conf type can not found:' + skill_id);
        return null;
    }
    return rebel_conf;
};

/**
 * 获取来袭的技能列表
 * @param  {[type]} rebel_id [description]
 * @return {[type]}          [description]
 */
exports.getRebelSkillList = function () {
    var skill_list = [];
    var rebel_conf = dataApi.rebel_skill.all();
    _.each(rebel_conf, function (rebel_item) {
        skill_list.push({
            skill_type: rebel_item.id,
            atk_type: rebel_item.atk_type,
            cd_time: rebel_item.cd_time,
            skill_time: rebel_item.skill_time,
            value: rebel_item.value,
            cost_gold: rebel_item.cost_gold
        });
    });
    return skill_list;
};

/**
 * 获取来袭的配置
 * @param  {[type]} copy_id [description]
 * @return {[type]}         [description]
 */
exports.getWaveConf = function (rebel_id) {
    return _getWaveConf(rebel_id);
};

var _getWaveConf = function (rebel_id) {
    return dataApi.rebel_config.findById(rebel_id);
};

var _getRebelConf = function (rebel_id) {
    return dataApi.rebel.findById(rebel_id);
};

var _getRebelSkillConf = function (skill_id) {
    return dataApi.rebel_skill.findById(skill_id);
};
